//
//  YSMMainTabBar.m
//  YSMWeibo
//
//  Created by 杨思明 on 16/7/24.
//  Copyright © 2016年 杨思明. All rights reserved.
//

#import "YSMMainTabBar.h"
#import <UIKit/UIKit.h>


@implementation YSMMainTabBar

-(void)layoutSubviews{
    
    [super layoutSubviews];
    
    UIButton *button = [[UIButton alloc]init];
    
    [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    [self addSubview:button];
    [button addTarget:self action:@selector(composeClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    int buttonCount = 5;
    
    CGFloat with = self.bounds.size.width / buttonCount;
    
    int index = 0;
    for (UIView * item in self.subviews) {
    
//        NSLog(@"%@",item);
        Class cla = NSClassFromString(@"UITabBarButton");
        if ([item isKindOfClass:cla]) {
            
            item.frame = CGRectMake(index * with, 0, with, self.frame.size.height);
            index++;
            if (index == 2) {
                
                button.frame = CGRectMake(2 * with, 0, with, self.frame.size.height);
                index++;
            }
            
        }
        
    }
    
}
-(void)composeClick{

    [[NSNotificationCenter defaultCenter] postNotificationName:@"YSMMainTabBar" object:nil];
    
}


@end
